home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_08_11
/
8n11105a
< prev
next >
Wrap
Text File
|
1990-08-07
|
906b
|
39 lines
******
Listing 4
#include <stdio.h>
struct s_date
{
int day;
int month;
char filler; /* Just to get some packing bytes (perhaps) */
int year;
};
main()
{
FILE *file;
static struct s_date date = {1,2,' ',3};
static struct s_date date2 = {4,5,' ',6};
printf("\n Size of the structure is %d",
sizeof(struct s_date));
/* Write two structures out */
file = fopen("DATA.DAT", "w");
fwrite(&date, sizeof(struct s_date), 1, file);
fwrite(&date2, sizeof(struct s_date), 1, file);
fclose(file);
file = fopen("DATA.DAT","r");
/* Note reversal of which date is read */
fread(&date2, sizeof(struct s_date), 1, file);
fread(&date, sizeof(struct s_date), 1, file);
fclose(file);
}
*********